package wangwenjun.phase2.concurrencypattern.eventbus.google.demo07;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import lombok.extern.slf4j.Slf4j;
import util.ThreadUtil;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author ChangLiang
 * @date 2020/6/19
 */
@Slf4j
public class OrderQueryHandler {

    private final EventBus eventBus;

    public OrderQueryHandler(EventBus eventBus) {
        this.eventBus = eventBus;
    }

    @Subscribe
    public void doOrderQuery(OrderQueryRequest request) {
        log.info("{} start query the orderNo:{}",this.getClass().getSimpleName(), request.toString());
        // mock real query
        ThreadUtil.sleepForMilliSeconds(ThreadLocalRandom.current().nextInt(200,1000));
        OrderQueryResponse response = new OrderQueryResponse("query result");
        this.eventBus.post(response);
    }
}
